var app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        my_ip: '',
        my_port: '',
        port: ''
    },

    //获取输入的接口------------
    bindinputip: function (e) {
        this.setData({
            my_ip: e.detail.value
        })
    },

    bindinputport: function (e) {
        this.setData({
            port: e.detail.value
        })
    },

    //接口保存全局后返回
    bindbutton: function (e) {
        wx.clearStorage()
        var that = this
        //获取code
        wx.login({
            success: function (res) {
                if (res.code) {
                    console.log('code:', res.code)
                    //保存到全局变量
                    app.globalData.code = res.code
                } else {
                    console.log('获取用户登录态失败！' + res.errMsg)
                }
            }
        });
        let ip = this.data.my_ip
        let pr = this.data.port
        let ss = ip.toLowerCase()
        let bb = pr.toLowerCase()
        let address = this.data.my_ip + this.data.port
        console.log(address)
        if (ss == "admin" && bb == "admin") {
            app.globalData.my_port = ss
            app.globalData.user_phone = "15385359505"
            wx.setStorage({
                key: 'user_phone',
                data: app.globalData.user_phone,
            })
            wx.setStorage({
                key: 'my_port',
                data: app.globalData.my_port,
            })
            wx.switchTab({
                url: "../msg/msg"
            })
            wx.request({
                url: 'https://' + app.globalData.url + '/staff/findStaffByLMOBILE',
                data: {
                    LMOBILE: app.globalData.user_phone
                },
                method: 'GET',
                dataType: 'json',
                responseType: 'text',
                header: {
                    'content-type': 'application/json;charset=utf-8'
                },
                success: function (res) {
                    if (res.data.success == true) {
                        that.setData({
                            table: res.data.obj
                        })
                        app.globalData.lusercode = that.data.table[0].LUSERCODE
                        app.globalData.lusername = that.data.table[0].LUSERNAME
                    } else {
                        // wx.navigateTo({
                        //     url: '../index/index',
                        // })
                        wx.showModal({
                            title: '提示',
                            content: '获取用户信息失败',
                            showCancel: false,
                            confirmText: '确定',
                            success(res) {
                                if (res.confirm) {
    
                                }
                            }
                        })
                    }
                },
                fail: function (res) {
                    wx.showModal({
                        title: '提示',
                        content: '访问服务器出错',
                        showCancel: false,
                        confirmText: '确定',
                        success(res) {
                            if (res.confirm) {
    
                            }
                        }
                    })
                },
            })
        } else if (address == '') {
            // address = ''
            app.globalData.my_port = ''
            wx.setStorage({
                key: 'my_port',
                data: '',
            });
            wx.navigateTo({
                url: "../index/index"
            })
            // wx.switchTab({
            //     url:"../home/home"
            // })
        } else if (address != '') {
            console.log(address)
            wx.showModal({
                title: '提示',
                content: '请输入正确的账号密码',
                success(res) {
                    if (res.confirm) {} else if (res.cancel) {}
                }
            })
        }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})